//用冒泡排序实现qsort,理解回调函数
void Print(int* p, int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", *(p + i));
	}
	printf("\n");
}

//比较整形数组
int comper(const void* p1, const void* p2)
{
	return *((int*)p1) - *((int*)p2);
}

void Sweap(void*p1,void*p2,size_t size)
{
	size_t i = 0;
	char tmp = 0;
	for (i = 0; i < size; i++)
	{
		tmp = *((char*)p1+i);
		*((char*)p1+i) = *((char*)p2+i);
		*((char*)p2+i) = tmp;
	}
}

void bubbl_sort(void* p, size_t numberlens, size_t size, int (*comper)(const void*, const void*))
{
	size_t i = 0;
	size_t j = 0;
	for (i = 0; i < numberlens - 1; i++)
	{
		for (j = 0; j < numberlens - 1 - i; j++)
		{
			if (comper((char*)p + j * size, (char*)p + (j + 1) * size)>0)
			{
				Sweap((char*)p + j * size, (char*)p + (j + 1) * size,size);
			}
		}
	}
}

int main()
{
	int arr[] = { 2,1,5,9,8,6,3,4,5,6,7,8 };
	int sz = sizeof(arr) / sizeof(int);
	bubbl_sort(arr, sz, sizeof(int), comper);
	Print(arr,sz);
	return 0;
}